Yes, there are several free and open-source tools that can help you monitor your GitHub repository for changes, pull the updated Dockerfile, build the Docker image, and then push it to Docker Hub. One popular tool for this purpose is GitHub Actions.
GitHub Actions is a CI/CD service provided by GitHub that allows you to automate workflows directly in your repository. Here's how you can set it up to monitor a repository for changes to a Dockerfile, build the Docker image, and push it to Docker Hub:
-
Create a GitHub Actions Workflow:
- In your GitHub repository, create a directory called
.github/workflows. - Inside this directory, create a file named
docker-build.yml(or any name you prefer).
- In your GitHub repository, create a directory called
-
Define the Workflow:
- Edit
docker-build.ymlwith the following content:
- Edit
name: Build and Push Docker Image
on:
push:
paths:
- Dockerfile
- '**/Dockerfile'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: $
password: $
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: username/repository:tag
-
Configure Secrets:
- Go to your GitHub repository settings.
- Navigate to "Secrets and variables" -> "Actions".
- Add the following secrets:
DOCKER_USERNAME: Your Docker Hub username.DOCKER_PASSWORD: Your Docker Hub password.
-
Customize the Workflow:
- Replace
username/repository:tagwith your actual Docker Hub repository and tag name.
- Replace
This setup will trigger the workflow whenever a change is pushed to any Dockerfile in the repository. The workflow will:
- Check out the repository.
- Set up Docker Buildx.
- Log in to Docker Hub.
- Build and push the Docker image.
Using GitHub Actions is a straightforward and integrated way to automate this process directly within your GitHub repository.